package grib2handler.grib.bean;

import java.util.List;

import grib2handler.util.CommonUtil;

/**
 * Grib基础类型,只有一维,被其他数据引用
 * @author charlie
 *
 */
public class GribBaseBean {
	private String name;//名称
	private int size;//个数
	private String[] items;//数据
	private double[] itemsDou;//转换成 double的数据
	private boolean status = true;
	/**
	 * 
	 * @param fileName 文件名 time(time=1).txt
	 * @param text 内容  6 
	 */
	public GribBaseBean(String fileName, String text) {
		try {
			List<String> list = CommonUtil.getTeacherList(fileName);
			name = list.get(0);
			String[] temp = list.get(0).split("=");
			size = Integer.parseInt(temp[1]);
			items = text.trim().split(" "); 
			if(size != items.length) {
				status = false;
			}
			itemsDou = new double[items.length];
			for (int i = 0; i < items.length; i++) {
				itemsDou[i] = Double.parseDouble(items[i]);
				//单位转换
				if(name.contains("isobaric")) {
					items[i] = String.valueOf((int)(itemsDou[i]/100));
				}
			}
		} catch (Exception e) {
			status = false;
		}
	}
	
	public GribBaseBean(String name, int size, String[] items, double[] itemsDou) {
		super();
		this.name = name;
		this.size = size;
		this.items = items;
		this.itemsDou = itemsDou;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getSize() {
		return size;
	}

	public void setSize(int size) {
		this.size = size;
	}

	public String[] getItems() {
		return items;
	}

	public void setItems(String[] items) {
		this.items = items;
	}

	public double[] getItemsDou() {
		return itemsDou;
	}

	public void setItemsDou(double[] itemsDou) {
		this.itemsDou = itemsDou;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
